package com.dao;

import com.tools.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class GradeDao {
    public static void updateGrade(int gradeId,int chinese, int math, int english, int java, int oracle) {
        Connection conn = null;
        PreparedStatement ps = null;

        try{
            conn = DBUtil.getConnection();
            String sql = "update  grade set chinese=?,math=?,english=?,java=?,oracle=? where gradeId=?";
            ps = conn.prepareStatement(sql);
            ps.setInt(1,chinese);
            ps.setInt(2,math);
            ps.setInt(3,english);
            ps.setInt(4,java);
            ps.setInt(5,oracle);
            ps.setInt(6,gradeId);
            ps.executeUpdate();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBUtil.close(conn,ps,null);
        }
    }

    /**
     * 删除学生成绩
     * @param gradeId
     */
    public static void deleteGrade(int gradeId) {
        Connection conn = null;
        PreparedStatement ps = null;

        try {
            conn = DBUtil.getConnection();
            String sql = "delete from grade where gradeId=?";
            ps = conn.prepareStatement(sql);
            ps.setInt(1, gradeId);
            ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(conn, ps, null);
        }
    }
}
